package org.example.component;

import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ComponentConfig 
{
	@Autowired
	MysqlChatMemoryStore mysqlChatMemoryStore;
	
	@Bean
	public ChatMemoryProvider chatMemoryProvider()
	{
		return new ChatMemoryProvider() {
			@Override
			public ChatMemory get(Object o) {	//这个o就是消息ID唯一标识
				return MessageWindowChatMemory.builder()
						.id(o)	//唯一标识
						.maxMessages(5)
						.chatMemoryStore(mysqlChatMemoryStore)	//配置提供ChatMemoryStore接口
						.build();
			}
		};
	}
}
